package com.oa.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.oa.bean.bazaar.Inten;
import com.oa.bean.work.Emp;
import com.oa.service.BazaarService;
import com.oa.util.Encoding;
import com.oa.util.Page;
import com.oa.util.WriteResult;
import com.opensymphony.xwork2.ActionSupport;

public class BazaarAction extends ActionSupport {

	private static final long serialVersionUID = 8827313554448942354L;

	private BazaarService bazaarService;
	
	private Emp emp;

	// 请求，响应
	private HttpServletRequest request;

	private HttpServletResponse response;

	// 意向学生
	private Inten inten;

	// 学生id
	private int intenId;

	public int getIntenId() {
		return intenId;
	}

	public void setIntenId(int intenId) {
		this.intenId = intenId;
	}

	public Emp getEmp() {
		return emp;
	}

	public void setEmp(Emp emp) {
		this.emp = emp;
	}

	// 意向学生集合
	private List<Object> rows;

	public List<Object> getRows() {
		return rows;
	}

	public Inten getInten() {
		return inten;
	}

	public void setInten(Inten inten) {
		this.inten = inten;
	}

	public void setBazaarService(BazaarService bazaarService) {
		this.bazaarService = bazaarService;
	}

	// 意向学生新增
	public String intenSave() {
		inten = new Inten();
		inten.setIntenname("张三");
		// -------以上是测试代码---------
		bazaarService.save(inten);
		return "inten_save";
	}

	// 意向学生删除
	public String intenDelete() {

		// -------以上是测试代码---------
		bazaarService.delete(inten);
		return "inten_delete";
	}

	// 意向学生修改
	public String intenUpdate() {
		inten = new Inten();
		inten.setIntenid(3);
		inten.setIntenname("李五");
		// -------以上是测试代码---------
		inten = bazaarService.update(inten);
		return "inten_update";
	}

	// 通过id查找意向学生
	public String queryById() {
		// -------以上是测试代码---------
		inten = bazaarService.queryById(intenId);
		System.out.println(inten);
		return "inten_update";
	}

	// 意向学生普通分页查询
	public String intenQueryPager() {
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
		rows = bazaarService.intenQueryPager(Page.getPage(request), Page.getPageSize(request));
		Encoding.setEncoding(request, response);
		System.out.println(rows);
		WriteResult.write(response, rows);
		return "inten_queryPager";
	}

	// 按名字分页查询意向学生
	public String intenPagerByName() {
		inten = new Inten();
		inten.setIntenname("四");
		// -------以上是测试代码---------
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
		rows = bazaarService.intenPagerByName(Page.getPage(request), Page.getPageSize(request), inten.getIntenname());
		Encoding.setEncoding(request, response);
		System.out.println(rows);
		WriteResult.write(response, rows);
		return "inten_queryPager";
	}

	// 按年龄分页查询意向学生
	public String intenPagerByAge() {
		inten = new Inten();
		inten.setIntenage(18);
		// -------以上是测试代码---------
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
		rows = bazaarService.intenPagerByAge(Page.getPage(request), Page.getPageSize(request), inten.getIntenage());
		Encoding.setEncoding(request, response);
		System.out.println(rows);
		WriteResult.write(response, rows);
		return "inten_queryPager";
	}

	// 按就读学校分页查询意向学生
	public String intenPagerByCollege() {
		inten = new Inten();
		inten.setIntensch("清华");
		// -------以上是测试代码---------
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
		rows = bazaarService.intenPagerByCollege(Page.getPage(request), Page.getPageSize(request), inten.getIntensch());
		Encoding.setEncoding(request, response);
		System.out.println(rows);
		WriteResult.write(response, rows);
		return "inten_queryPager";
	}

	// 按出生地分页查询意向学生
	public String intenPagerByBirthplace() {
		inten = new Inten();
		inten.setIntenaddr("江西");
		// -------以上是测试代码---------
		request = ServletActionContext.getRequest();
		response = ServletActionContext.getResponse();
		rows = bazaarService.intenPagerByBirthplace(Page.getPage(request), Page.getPageSize(request),
				inten.getIntenaddr());
		Encoding.setEncoding(request, response);
		System.out.println(rows);
		WriteResult.write(response, rows);
		return "inten_queryPager";
	}
	
	//添加招生管理员
	public String zhaoAdminAdd(){
		Emp e = bazaarService.zhaoAdminAdd(emp);
		System.out.println(e.toString());
		return SUCCESS;
	}
	
	//修改招生管理员
	public String zhaoAdminUpdate(){
		Emp e = bazaarService.zhaoAdminUpdate(emp);
		System.out.println(e.toString());
		return SUCCESS;
	}
	
	//冻结招生管理员
	public String zhaoAdminDong(){
		bazaarService.zhaoAdminDong(emp);
		return SUCCESS;
	}
	
	//招生管理员分页
	public String zhaoAdminQueryPage(){
		List<Emp> emp = bazaarService.zhaoAdminQueryPager(0, 3);
		for(Emp e : emp){
			System.out.println(e.toString());
		}
		return SUCCESS;
	}

}
